﻿package mortal.component.window.resWin
{
    import com.gengine.resource.*;
    import flash.display.*;
    import flash.utils.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.view.signUp.view.*;
    import mortal.mvc.interfaces.*;

    public class ResBasePanel extends SignUpViewBase implements IResWin
    {
        private var _isRegistedToolTip:Boolean = false;
        protected var _iUIViewParent:IUIView;
        private var _isLoadComplete:Boolean = false;
        private var _uiRes:String;
        private var _window:IResWin;

        public function ResBasePanel(param1:String = null, param2:IResWin = null)
        {
            this._uiRes = param1;
            this._window = param2;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            if (this.hasRes)
            {
                LoaderHelp.addResCallBack(this._uiRes, this.onResLoadComplete);
            }
            else
            {
                this._isLoadComplete = true;
                this.layoutUI();
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._isLoadComplete = false;
            return;
        }// end function

        private function onResLoadComplete() : void
        {
            this._isLoadComplete = true;
            this.layoutUI();
            this.refresh(true);
            return;
        }// end function

        public function layoutUI() : void
        {
            return;
        }// end function

        public function display(param1:int = 0, param2:int = 0) : void
        {
            throw new Error("不是窗口类，不能调用此方法!");
        }// end function

        public function refresh(param1:Boolean = false) : void
        {
            if (this.allowRefresh && param1)
            {
                this.loadData();
            }
            return;
        }// end function

        protected function get allowRefresh() : Boolean
        {
            return !this.isHide && this.isLoadComplete;
        }// end function

        protected function loadData() : void
        {
            return;
        }// end function

        public function get isHide() : Boolean
        {
            return this.iUIViewParent.isHide;
        }// end function

        public function get iUIViewParent() : IUIView
        {
            var _loc_1:String = null;
            var _loc_2:DisplayObjectContainer = null;
            if (this._iUIViewParent)
            {
                if (this._window == null && this._iUIViewParent is IResWin)
                {
                    this._window = IResWin(this._iUIViewParent);
                }
                return this._iUIViewParent;
            }
            else
            {
                if (this._window && this._window is IUIView)
                {
                    this._iUIViewParent = IUIView(this._window);
                    return this._iUIViewParent;
                }
                _loc_1 = getQualifiedClassName(this);
                _loc_2 = this;
                do
                {
                    
                    if (_loc_2 is IUIView)
                    {
                        this._iUIViewParent = _loc_2 as IUIView;
                        return this._iUIViewParent;
                    }
                    var _loc_3:* = _loc_2.parent;
                    _loc_2 = _loc_2.parent;
                }while (_loc_3)
            }
            throw new Error("没有将 " + _loc_1 + " 通过addChild()方法到实现IUIView接口父级下的容器");
        }// end function

        public function get isLoadComplete() : Boolean
        {
            return this._isLoadComplete;
        }// end function

        public function get rect3DObject() : Rect3DObject
        {
            if (this._window)
            {
                return this._window.rect3DObject;
            }
            return null;
        }// end function

        private function get hasRes() : Boolean
        {
            return this._uiRes && this._uiRes != "";
        }// end function

    }
}
